#!/usr/bin/env python3

import sys
import os


def parse_conf(_f, upper_level, num, start_num, flags):
    _ret = 0
    max_level = -1
    cycle = 0
    this_level_cycle = 0
    total_num = 0
    last_idx = 0
    cur_num = int(num) - int(start_num)
    before = 1
    with open(_f, 'r') as _fd:
        for _ll in _fd.readlines():

            # skip null lines
            if not _ll:
                continue

            # skip comment lines
            if _ll.find("#") == 0:
                continue

            total_num += 1
            if total_num < int(start_num):
                continue

            # get kv
            eidx = _ll.find("(")
            if eidx == -1:
                print("WARNNING: not = find in " + _ll);
                continue
            level = upper_level
            tmpidx = _ll.find("+-")
            if tmpidx == -1:
                tmpidx = _ll.find("\-")
                if tmpidx != -1 and eidx != -1:
                    level = tmpidx >> 1
                    key = _ll[0:tmpidx].strip()
                    val = _ll[tmpidx+2:eidx].strip()
                    count = 0;
                    level += count
                    sub_idx = _ll.find("|")
                    tmp_level = level
                    if sub_idx != -1:
                        tmp_level = (tmpidx - sub_idx) >> 1
                    if tmp_level > level:
                        level = tmp_level
            else:
                if last_idx == tmpidx:
                    last_idx = 0
                level = tmpidx >> 1
                key = _ll[0:tmpidx].strip()
                val = _ll[tmpidx+2:eidx].strip()
                sub_idx = _ll.find("|")
                tmp_level = level
                if sub_idx != -1:
                    tmp_level = (tmpidx - sub_idx) >> 1
                if tmp_level > level:
                    level = tmp_level
                if last_idx != 0:
                    level += 1
            cycle += 1
            if int(flags) != 20:
                if level == int(upper_level) and cycle > 1:
                    break
                if level == int(upper_level):
                    continue
                if level >= int(upper_level) + 2:
                    continue
                if level <= int(upper_level) and this_level_cycle >  int(cur_num):
                    break

            before = 0
            if level <= int(upper_level):
                continue
            this_level_cycle += 1
            if this_level_cycle < int(cur_num):
                continue
            if this_level_cycle > int(cur_num) and int(cur_num) != 0:
                break
            if int(flags) == 1:
                print(val)
            elif int(flags) == 0:
                print("NULL")
            else:
                print(total_num)

            if max_level < level:
                max_level = level
            break

    return _ret

if __name__ == "__main__":

    _f1 = sys.argv[1];
    level = sys.argv[2];
    num = sys.argv[3];
    start = sys.argv[4];
    print_flags = sys.argv[5];

    _kv1 = parse_conf(_f1, level, num, start, print_flags);
